package com.shop.milk_tea_shop.controller;

import com.shop.milk_tea_shop.common.CodeEnum;
import com.shop.milk_tea_shop.common.GlobalInfo;
import com.shop.milk_tea_shop.common.Result;
import com.shop.milk_tea_shop.entity.ShopInfo;
import com.shop.milk_tea_shop.request.ShopQueryRequest;
import com.shop.milk_tea_shop.service.ShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 店铺信息表：	和店长一一对应，店长登陆即可管理开店 前端控制器
 * </p>
 *
 * @author yjw
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/shopInfo")
public class ShopInfoController {

    @Autowired
    private ShopInfoService shopInfoService;

    @PostMapping("/paged")
    public Result<List<ShopInfo>> paged(ShopQueryRequest request) {
        System.out.println(request);
        return shopInfoService.paged(request);
    }

    @GetMapping("/{id}")
    public Result<ShopInfo> getById(@PathVariable Long id) {
        ShopInfo shopInfo = shopInfoService.getById(id);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, shopInfo, new GlobalInfo());
    }

    @PostMapping("/add")
    public Result<Boolean> add(ShopInfo shop) {
        boolean result = shopInfoService.save(shop);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, result, new GlobalInfo());
    }

    @PutMapping
    public Result<Boolean> update(ShopInfo shop) {
        boolean result = shopInfoService.updateById(shop);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, result, new GlobalInfo());
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        ShopInfo shop = new ShopInfo();
        shop.setShopId(id);
        shop.setStatus(0);
        return update(shop);
    }
}
